package com.ruoyi.system.service.zhaungxiuservice.shopService.impl;

import com.ruoyi.system.domain.supe.PlatformCoupon;
import com.ruoyi.system.mapper.zhuangxiumapper.PlatformCouponMapper;
import com.ruoyi.system.service.zhaungxiuservice.shopService.PlatformCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class PlatformCouponServiceImpl implements PlatformCouponService {


    @Autowired(required = false)
    private PlatformCouponMapper platformCouponMapper;

    /**
     * 查询平台优惠卷
     *
     * @param platformId 平台优惠卷ID
     * @return 平台优惠卷
     */
    @Override
    public PlatformCoupon selectPlatformCouponById(Integer platformId)
    {
        return platformCouponMapper.selectPlatformCouponById(platformId);
    }

    /**
     * 查询平台优惠卷列表
     *
     * @param platformCoupon 平台优惠卷
     * @return 平台优惠卷
     */
    @Override
    public List<PlatformCoupon> selectPlatformCouponList(PlatformCoupon platformCoupon)
    {
        return platformCouponMapper.selectPlatformCouponList(platformCoupon);
    }

    @Override
    public List<PlatformCoupon> findAllList() {
        return platformCouponMapper.findAllList();
    }

    /**
     * 新增平台优惠卷
     *
     * @param platformCoupon 平台优惠卷
     * @return 结果
     */
    @Override
    public int insertPlatformCoupon(PlatformCoupon platformCoupon)
    {

        Date platformTimeStart = platformCoupon.getPlatformTimeStart();
        Date platformTimeEnd = platformCoupon.getPlatformTimeEnd();

        if (platformTimeStart.after(platformTimeEnd)){
            return 0;
        }else {
            platformCoupon.setModifiedTime(new Date());
            return platformCouponMapper.insertPlatformCoupon(platformCoupon);
        }
    }

    /**
     * 修改平台优惠卷
     *
     * @param platformCoupon 平台优惠卷
     * @return 结果
     */
    @Override
    public int updatePlatformCoupon(PlatformCoupon platformCoupon)
    {
        return platformCouponMapper.updatePlatformCoupon(platformCoupon);
    }

    @Override
    public int updateStateCou(PlatformCoupon platformCoupon) {
        return platformCouponMapper.updateStateCou(platformCoupon);
    }

    /**
     * 批量删除平台优惠卷
     *
     * @param platformIds 需要删除的平台优惠卷ID
     * @return 结果
     */
    @Override
    public int deletePlatformCouponByIds(Integer[] platformIds)
    {
        return platformCouponMapper.deletePlatformCouponByIds(platformIds);
    }

    /**
     * 删除平台优惠卷信息
     *
     * @param platformId 平台优惠卷ID
     * @return 结果
     */
    @Override
    public int deletePlatformCouponById(Integer platformId)
    {
        return platformCouponMapper.deletePlatformCouponById(platformId);
    }

    @Override
    public int findAllSum() {
        return platformCouponMapper.findAllSum();
    }
}
